package action.activity;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.interceptor.ServletRequestAware;
import po.User;
import service.ActivityService;
import service.OrgService;
/**
 *
 * @author HX
 */
public class SubmitActivityNewsAction extends ActionSupport implements ServletRequestAware{
    private HttpServletRequest request;
    private String activityTitle;
    int orgId;
    private OrgService orgService;

    @Override
    public String execute()
    {
        String activityName;
        String msg;
        int userId;
        if(request.getParameter("orgId")==null)
         {
             msg="no org id!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
        orgId = Integer.parseInt(request.getParameter("orgId"));
        if (ActionContext.getContext().getSession().get("user") == null) {
            msg = "you should login first";
            request.setAttribute("msg", msg);
            return ERROR;
         }
        userId = ((User) ActionContext.getContext().getSession().get("user")).getId();

        if(!orgService.isLeader(userId, orgId)){
            msg = "you can not submit a news!";
            request.setAttribute("msg", msg);
            return ERROR;
        }
        if(request.getParameter("activityName")==null)
         {
             msg="no activityName!!!";
             request.setAttribute("msg", msg);
             return ERROR;
         }
        activityName = request.getParameter("activityName");
        activityTitle = "[活动新闻]" + activityName;

        return SUCCESS;

    }

    public void setActivityTitle(String activityTitle)
    {
        this.activityTitle=activityTitle;
    }

    public String getActivityTitle()
    {
        return this.activityTitle;
    }

    public int getOrgId() {
        return orgId;
    }

    public void setOrgId(int orgId) {
        this.orgId = orgId;
    }

    public void setOrgService(OrgService orgService)
    {
        this.orgService=orgService;
    }

    public OrgService getOrgService()
    {
        return this.orgService;
    }

    public void setServletRequest(HttpServletRequest request)
    {
        this.request=request;
    }
}



